package com.xy.usermanagement.accountmanagement.service.impl;

import com.github.pagehelper.PageHelper;
import com.xy.model.Author;
import com.xy.model.PageList;
import com.xy.model.UserStatus;
import com.xy.usermanagement.accountmanagement.mapper.UserStatusMapper;
import com.xy.usermanagement.accountmanagement.service.IAccountManagementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
public class AccountManagementServiceImpl implements IAccountManagementService {
		@Autowired
		private UserStatusMapper mapper;

		@Override
		@Transactional
		public Integer changeAccount(UserStatus user) {
				log.info("AccountManagementServiceImpl changeAccount=> user : "+user);
				int i = -1;
				try {
						i = mapper.updateByPrimaryKey(user);
				} catch (Exception e) {
						e.printStackTrace();
				}
				return i;
		}

		@Override
		public PageList<UserStatus> getBanAccount(Integer pageNum, Integer pageSize) {
				log.info("AccountManagementService getBanAccount pageNum = "+pageNum);
				log.info("AccountManagementService getBanAccount pageSize = "+pageSize);
				if (pageNum == null) {
						pageNum = 1;
				}
				if (pageSize == null) {
						pageSize = 20;
				}
				PageHelper.startPage(pageNum, pageSize);
				List<UserStatus> list = null;
				try {
						list = mapper.selectAllAbnormal();
				} catch (Exception e) {
						log.error("错误消息：{}", e.getMessage(), e);
				}
				log.info("AccountManagementService getBanAccount=>list = "+list);
				return new PageList<>(list);
		}

		@Override
		public PageList<UserStatus> getUnlockAccount(Integer pageNum, Integer pageSize) {
				log.info("AccountManagementService getUnlockAccount pageNum = "+pageNum);
				log.info("AccountManagementService getUnlockAccount pageSize = "+pageSize);
				if (pageNum == null) {
						pageNum = 1;
				}
				if (pageSize == null) {
						pageSize = 20;
				}
				PageHelper.startPage(pageNum, pageSize);
				List<UserStatus> list = null;
				try {
						list = mapper.selectAllNormal();
				} catch (Exception e) {
						log.error("错误消息：{}", e.getMessage(), e);
				}
				log.info("AccountManagementService getUnlockAccount=>list = "+list);
				return new PageList<>(list);
		}

		@Override
		public PageList<UserStatus> getAllAccount(Integer pageNum, Integer pageSize) {
				log.info("AccountManagementService getAllAccount pageNum = "+pageNum);
				log.info("AccountManagementService getAllAccount pageSize = "+pageSize);
				if (pageNum == null) {
						pageNum = 1;
				}
				if (pageSize == null) {
						pageSize = 20;
				}
				PageHelper.startPage(pageNum, pageSize);
				List<UserStatus> list = null;
				try {
						list = mapper.selectAll();
				} catch (Exception e) {
						log.error("错误消息：{}", e.getMessage(), e);
				}
				log.info("AccountManagementService getAllAccount=>list = "+list);
				return new PageList<>(list);
		}
}
